/**
* m3u8转json对象
*@since 2021年3月30日22:26:19
*@author 284949127
*@link https://www.166396.com/20200710/3A7tjNT1/index.m3u8
*/
function m3u8tojson(x){
let cache=m3u8tojson.prototype.cache;
if(!cache)m3u8tojson.prototype.cache=cache={};
let hash=hashCode(x);
if(!!cache[''+hash])return cache[''+hash];
let xx=x.split('\n');
let xxx=[];xx.forEach(e=>e.startsWith('#')?xxx.push(e):xxx[xxx.length-1]+=e);
let xxxx=[];xxx.forEach(e=>{ let sp=e.replace('#','').split(':');
let k=sp[0];let v=sp[1];
v=!v||!v.includes(',')?v:!v.includes('=')?v.split(','):Object.assign(... v.split(',').map( ve=>({[ve.split('=')[0]]:ve.split('=')[1]})));
xxxx.push({[k]:v});});
let xxxxx={};let pk=[];xxxx.forEach(e=>{let k=Object.keys(e)[0];let v=e[k];
if(xxxxx.hasOwnProperty(k)){if(xxxxx[k] instanceof Array&&pk.includes(k)){xxxxx[k].push(v);}else{xxxxx[k]=[xxxxx[k],v];pk.push(k);};}
else{xxxxx[k]=v;}});
cache[''+hash]=xxxxx;
console.log('nocache')
return xxxxx;
}

/**
*与java计算结果一致
*@link http://www.zkea.net/codesnippet/detail/javascript-hash.html
*/
function hashCode(value) {
  var hash = 0, i, chr;
  if (value.length === 0) return hash;
  for (i = 0; i < value.length; i++) {
    chr   = value.charCodeAt(i);
    hash  = ((hash << 5) - hash) + chr;
    hash |= 0; // Convert to 32bit integer
  }
  return hash;
};